import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'

import '@/styles/index.scss' // global css
import exoprt_excel from '@/utils/expor_file_excel' // 导出excel文件
import exoprt_excel2 from '@/utils/expor_file_excel2' // 导出excel文件
import App from './App'
import store from './store'
import router from './router'
import i18n from './lang' // internationalization
import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters
import getPdf from '@/utils/htmlToPdf' // global filters
Vue.prototype.getPdf = getPdf
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})

import FileSaver from 'file-saver'
import * as XLSX from 'xlsx';
import { write, utils } from 'xlsx';
Vue.prototype.$Excel= function(list , dom) {
  let table = document.getElementById(dom)
  var name = 'file_'+dom
  let et = utils.table_to_book(table)
    let output = write(et, {
      bookType: "xlsx",
      bookSST: true,
      type: "array"
    })
    FileSaver.saveAs(new Blob([output], { type: "application/octet-stream" }), `${name}.xlsx`)
     try {

      } catch (e) {
      }
	//导出excel
  return output
}
Vue.prototype.$export_down = (URLs , data , name , type)=>{
  return  new Promise(function(resolve, reject) {
    exoprt_excel(URLs , data , name , type).then(res=>{
      resolve()
    }).catch(err=>{
      reject()
    })

  })

} //导出excel文件
Vue.prototype.$geShi = function (ob) {
        ob = ob.replace(/[^\d.]/g,""); // 清除"数字"和"."以外的字符
        ob = ob.replace(/^\./g,""); // 验证第一个字符是数字而不是.
        ob = ob.replace(/\.{2,}/g,"."); // 只保留第一个. 清除多余的
        ob = ob.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        ob = ob.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); // 只能输入两个小数
        if (ob.indexOf(".") < 0 && ob !== "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的数字
            ob = parseFloat(ob);
        }
        return ob
    }
Vue.prototype.$export_down2 = (URLs , data , name , type)=>{
  return  new Promise(function(resolve, reject) {
    exoprt_excel2(URLs , data , name , type).then(res=>{
      resolve()
    }).catch(err=>{
      reject()
    })

  })

} //导出excel文件
function getUrlParams() {
         var url = window.location.href
          var params = {};
          url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, value) {
              params[key] = value;
          });
          return params;
      }
Vue.prototype.$getUrlParams = getUrlParams

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
